package epin.fujiajun.sort.merge;

import epin.fujiajun.data.Array;
import epin.fujiajun.sort.ArraySortBase;

/**
 * Created by DELL on 2017/8/29.
 */
public abstract class Original extends ArraySortBase {

    protected Array[] aux;

    protected void merge(Array[] a, int low, int middle, int high) {

        for (int k = low;k <= high;k++){
            aux[k] = a[k];
        }

        int i = low;
        int j = middle + 1;

        for (int k = low;k <= high;k++){
            if (i > middle && j <= high){
                a[k] = aux[j++];
                continue;
            }

            if (j > high && i <= middle){
                a[k] = aux[i++];
                continue;
            }

            if (less(aux[i], aux[j]))
                a[k] = aux[i++];
            else
                a[k] = aux[j++];
        }

    }

}
